<?php

namespace Controller\Blind;

class Search extends \Controller\Base {

	public function actionIndex() {
		$this->setCurrentMenuKey('Blind');
		$params = $this->getRouteParams();
		$city = !empty($params[0]) ? (int) $params[0] : 0;
		$breed = !empty($params[1]) ? $params[1] : '';
		$breed = $breed ? urldecode($breed) : '';
		$breed = htmlspecialchars($breed);
		$sex = !empty($params[2]) ? (int) $params[2] : 0;
		$page = !empty($params[3]) ? (int) $params[3] : 0;
		$pager = new \Lib\Core\Pager();
		$pager->currentPage = $page;
		$dogs = \Business\User::instance()->search($pager, $city, $breed, $sex);

		$cityInfo = array();
		if ($city) {
			$cityInfo = \Business\City::instance()->getCityInfoByCode($city);
		}

		$articles = \Business\Article::instance()->getRightArticles(5);
		$this->assign('articles', $articles);
		$this->assign('cityInfo', $cityInfo);
		$this->assign('city', $city);
		$this->assign('breed', $breed);
		$this->assign('sex', $sex);
		$this->assign('pager', $pager);
		$this->assign('dogs', $dogs);
		$this->display();
	}
}